use crate::get_path::get_path;
use super::player_process::PlayerManager;
use once_cell::sync::Lazy;
use crate::db::{db_insert::db_insert, db_select::db_select};
use super::MediaType;
use super::AUDIO_AVAILABLE_DEFAULT;
use super::VIDEO_AVAILABLE_DEFAULT;

static PLAYER_MANAGER: Lazy<PlayerManager> = Lazy::new(PlayerManager::new);

pub async fn play() {
    // let path = get_path();
    if(get_video_available().await) {
        PLAYER_MANAGER.play_sdp(MediaType::Video).await.unwrap();
    }
    if(get_audio_available().await) {
        PLAYER_MANAGER.play_sdp(MediaType::Audio).await.unwrap();
    }
}
pub async fn stop() {
    PLAYER_MANAGER.stop_all().await;
}

pub async fn set_video_available(available: bool) {
    db_insert("video_available", available.to_string().as_str()).await.unwrap();
}

pub async fn set_audio_available(available: bool) {
    db_insert("audio_available", available.to_string().as_str()).await.unwrap();

}

pub async fn get_video_available() -> bool {
    if let Ok(value) = db_select("video_available").await {
        let available = value.value.parse::<bool>().unwrap();
        return available;
    } else {
        return VIDEO_AVAILABLE_DEFAULT;
    }
}

pub async fn get_audio_available() -> bool {
    if let Ok(value) = db_select("audio_available").await {
        let available = value.value.parse::<bool>().unwrap();
        return available;
    } else {
        return AUDIO_AVAILABLE_DEFAULT;
    }
}